package com.binance.basedao.mybatis;

import com.binance.basedao.complexquery.CustomQueryParam;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <b>Description:</b>〈数据库基础操作接口〉<br/>
 * @author hongchaoMao <br/>
 *         Create date: 2017/9/18
 * @version v1.0.0
 */
 public interface BaseMapper<T> {
    
    @SelectProvider(type = BaseProvider.class, method = "getAll")
    @Options(flushCache = Options.FlushCachePolicy.FALSE)
    @ResultMap("getMap")
    List<T> getAll();
    
    @SelectProvider(type = BaseProvider.class, method = "getById")
    @Options(flushCache = Options.FlushCachePolicy.FALSE)
    @ResultMap("getMap")
    T getById(@Param("id") Long id);
    
    @SelectProvider(type = BaseProvider.class, method = "count")
    @Options(flushCache = Options.FlushCachePolicy.FALSE)
    int count(T params);
    
    @SelectProvider(type = BaseProvider.class, method = "countLike")
    @Options(flushCache = Options.FlushCachePolicy.FALSE)
    int countLike(T findParams);
    
    @SelectProvider(type = BaseProvider.class, method = "countQuery")
    @Options(flushCache = Options.FlushCachePolicy.FALSE)
    int countQuery(@Param("queryParams") List<CustomQueryParam> customQueryParams);
    
    @SelectProvider(type = BaseProvider.class, method = "get")
    @Options(flushCache = Options.FlushCachePolicy.FALSE)
    @ResultMap("getMap")
    T getOne(T findParams);
    
    @SelectProvider(type = BaseProvider.class, method = "query")
    @Options(flushCache = Options.FlushCachePolicy.FALSE)
    @ResultMap("getMap")
    List<T> query(@Param("queryParams") List<CustomQueryParam> customQueryParams,
                  @Param("sortList") List<Sort> sortList);

    @SelectProvider(type = BaseProvider.class, method = "get")
    @Options(flushCache = Options.FlushCachePolicy.FALSE)
    @ResultMap("getMap")
    List<T> get(T findParams);

    @SelectProvider(type = BaseProvider.class, method = "enhanceGet")
    @Options(flushCache = Options.FlushCachePolicy.FALSE)
    @ResultMap("getMap")
    List<T> enhanceGet(@Param("findParams")T findParams, @Param("sortList") List<Sort> sortList);

    @SelectProvider(type = BaseProvider.class, method = "find")
    @Options(flushCache = Options.FlushCachePolicy.FALSE)
    @ResultMap("getMap")
    List<T> find(T findParams);
    
    @InsertProvider(type = BaseProvider.class, method = "insert")
    @Options(flushCache = Options.FlushCachePolicy.TRUE)
    int insert(@Param("model") T model, @Param("ignore") Boolean insertIgnore);
    
    @InsertProvider(type = BaseProvider.class, method = "insertBatch")
    @Options(flushCache = Options.FlushCachePolicy.TRUE)
    int insertBatch(@Param("list") List<T> list, @Param("ignore") Boolean insertIgnore);
    
    @DeleteProvider(type = BaseProvider.class, method = "deleteById")
    @Options(flushCache = Options.FlushCachePolicy.TRUE)
    int deleteById(Long id);
    
    @DeleteProvider(type = BaseProvider.class, method = "deleteByPrimaryKey")
    @Options(flushCache = Options.FlushCachePolicy.TRUE)
    int deleteByPrimaryKey(T t);
    
    @UpdateProvider(type = BaseProvider.class, method = "update")
    @Options(flushCache = Options.FlushCachePolicy.TRUE)
    int update(T t);
    
}
